function tree(arr, id = '') {
  const newArr = []
  arr.forEach(item => {
    if (item.pid === id) {
      newArr.push(item)
      const children = tree(arr, item.id)
      if (children.length) {
        item.children = children
      }
    }
  })
  return newArr
}
export default tree
